<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
          border-bottom: 1px solid #ccc;
          width: 400px;
          position: relative;
          margin: 100px auto;
        }
        .box input {
          border: 0;
          width: 100%;
          height: 40px;
          outline: none;
        }
        .box img {
          position: absolute;
          top: 12px;
          right: 2px;
          width: 30px;
          height: 30px;
          cursor: pointer;
        }
      </style>
</head>
<body>
    <div class="box">
        <input type="text">
        <img src="./images/open.png" alt="">
    </div>

    <script>
        var eye = document.querySelector('img');
        var input = document.querySelector('input');
        var flag = true;
        eye.onclick = function (){
           if(flag){
            eye.src = './images/close.png';
            flag = false;
            input.type = 'password';
           }else {
            eye.src = './images/open.png';
            flag = true;
            input.type = 'text';
           }
        }
    </script>
</body>
</html>